﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using System.Reflection.Metadata.Ecma335;

namespace Entity
{
    public class SMDBContext:DbContext
    {
        
        public SMDBContext(DbContextOptions<SMDBContext> opts): base(opts)
        {
           
        }

        /// <summary>
        /// 账户
        /// </summary>
        //public DbSet<Account> Accounts { get; set; }

        /// <summary>
        /// 用户信息
        /// </summary>
        public DbSet<User> user { get; set; }

        ///// <summary>
        ///// 报名表
        ///// </summary>
        //public DbSet<EnrollTable> EnrollTables { get; set; }
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    optionsBuilder.UseMySql("", new MySqlServerVersion(new Version(9, 2, 0)));
        //}

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            User user = new User();
            user.Name = "zhangsan";
            user.Age = 19;
            user.CellPhone = "11111111111";

            modelBuilder.Entity<User>().HasData([user]);
            modelBuilder.Entity<User>().HasData([
                new User{
                    Name = "LiSi",
                    Age = 20,
                    CellPhone = "22222222222",
                },
                new User{
                    Name = "WangWu",
                    Age = 21,
                    CellPhone = "33333333333",
                }
                ]);

        }
    }

    public class SMDBContextFactory : IDesignTimeDbContextFactory<SMDBContext>
    {
        

        SMDBContext IDesignTimeDbContextFactory<SMDBContext>.CreateDbContext(string[] args)
        {
            var optionBuilder = new DbContextOptionsBuilder<SMDBContext>();
            optionBuilder.UseMySql("server=localhost;userid=root;password=123456;database=AIYDB", new MySqlServerVersion(new Version(8, 0, 41)));

            return new SMDBContext(optionBuilder.Options);
        }
    }

    
}
